define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cms/grapevine/index' + location.search,
                    add_url: 'cms/grapevine/add',
                    edit_url: 'cms/grapevine/edit',
                    del_url: 'cms/grapevine/del',
                    multi_url: 'cms/grapevine/multi',
                    import_url: 'cms/grapevine/import',
                    table: 'grapevine',
                    add_form_url: 'cms/grapevine/add_form_url', //添加接口路径，方法名称要跟接口名称一致
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                search:false,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'form_url', title: __('Form_url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {
                            field: 'is_show',
                            title: __('Is_show'),
                            searchList: {"0": __('否'), "1": __('是')},
                            formatter: Table.api.formatter.normal
                        },
                        // {field: 'status', title: __('Status'), searchList: {"0":__('否'),"1":__('是'),"2":__('抓取错误')}, formatter: Table.api.formatter.status},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 1.工具栏自定义弹窗绑定事件
            $("#testButton").on('click', function (){
                // Fast.config.openArea = ['800px','600px']; //设置弹窗宽高,注意这里是全局调整
                Fast.api.open($.fn.bootstrapTable.defaults.extend.add_form_url,'抓取文章');
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        //2.为表格绑定事件
        add_form_url: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
